#include "stdafx.h"
#include "Solution.h"

int Solution::getDecimalValue(ListNode* head) {
    int result = 0;
    // loop invariant
    // [head: nullptr) is the todo range
    // result is the result of done range
    while (head) {
        result = result * 2 + head->val;
        head = head->next;
    }
    // post condition: 
    // head == nullptr 
    return result;
}